home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 440_01 / examp002.c < prev    next >
C/C++ Source or Header  |  1994-09-11  |  19KB  |  385 lines

  1. /*==========================================================================
  2.  *
  3.  *  EXAMP002.C                                    Sunday, September 11, 1994
  4.  *
  5.  *  sample source code for The BESTLibrary, intended to give examples of:
  6.  *    txt_fade_in
  7.  *    txt_fade_out
  8.  *    txt_fill_area
  9.  *    txt_flood
  10.  *    txt_print
  11.  *    txt_set_act
  12.  *    txt_set_vis
  13.  *    txt_str_show
  14.  *
  15.  *  Authored independently by George Vanous
  16.  *
  17.  *==========================================================================*/
  18.  
  19.  
  20. /* ------------------------------------------------------------------------ */
  21. /* ----------------------------  INCLUDE FILES  --------------------------- */
  22.  
  23. #include <alloc.h>
  24. #include <stdlib.h>
  25. #include "!bestlib.h"                  /* include !BESTLIB.H in compilation */
  26.  
  27. /* ------------------------------------------------------------------------ */
  28. /* ------------------------------  CONSTANTS  ----------------------------- */
  29.  
  30. #define BGCLR BLUE                              /* background color         */
  31. #define TEXTHEIGHT 12                           /* y-height of printed text */
  32. #define BUFFERSPACE 100                         /* byte size of "buffer"    */
  33. #define PRINT(x, y, text) _16_boxfill(x, y+2, textwidth(text), TEXTHEIGHT-2, BLACK, COPY_IMAGE); outtextxy(x, y, text);
  34.  
  35. /* ------------------------------------------------------------------------ */
  36. /* ------------------------------  MESSAGES  ------------------------------ */
  37.  
  38. #define ERR01 "\nI require 65,536 bytes (64kb) of free memory\nBut there is only %ld bytes currently available\n\nDo you want me to continue regardless [y/N] ? "
  39. #define MSG01 "\n\nI suggest you try removing any unnecessary TSRs (Terminate but Stay Resident\nprograms) to increase the amount of available memory.\n\n"
  40. #define DASHES printf("\n--------------------------------------------------------------------------------")
  41.  
  42. /* ------------------------------------------------------------------------ */
  43. /* -------------------------  GLOBAL DEFINITIONS  ------------------------- */
  44.  
  45. /* The following three definition are required by TheBESTLibrary to be
  46.    present, even if they are not all used.  If they are not present, the
  47.    compiler will produce a "linker error". */
  48. asciiscan key;                         /* global structure "key"            */
  49. cursordata cursor;                     /* global structure "cursor"         */
  50. mousedata msdata;                      /* global structure "msdata"         */
  51.  
  52. filldata fidata;                       /* global structure "fidata"         */
  53. printdata prdata;                      /* global structure "prdata"         */
  54.  
  55. byte curx, cury,                       /* the cursor (x,y)                  */
  56.      oldmode;                          /* old video mode                    */
  57. char *buffer;                          /* general-purpose string buffer     */
  58.  
  59. /* ------------------------------------------------------------------------ */
  60. /* -------------------------  FUNCTION PROTOTYPES  ------------------------ */
  61.  
  62. void begin_sequence(void);                      /* beginning sequence       */
  63. void draw_menu(void);                           /* display main menu        */
  64. void exit_sequence(void);                       /* exitting sequence        */
  65. void mouse_demo(void);                          /* demonstrate mouse        */
  66. void floodtext(char *text[]);                   /* part of "mouse_demo"     */
  67. void showtext(char *text[]);                    /* part of "mouse_demo"     */
  68. void string_demo(void);                         /* demonstrate strings      */
  69. void text_animate(void);                        /* animates text            */
  70. void text_fade(void);                           /* demonstrate text fading  */
  71.  
  72. void (*menuselect[])(void) = {                  /* pointer to functions     */
  73.   text_fade, mouse_demo, string_demo, text_animate
  74. };
  75.  
  76. /* ------------------------------------------------------------------------ */
  77.  
  78.  
  79. /*----------------------------------------------------------------------------
  80.  * MAIN SUBROUTINE OF EXAMPLE SOURCE CODE 002
  81.  */
  82. void main(void)
  83. {
  84.   int choice,                          /* user's menu choice                */
  85.       count;
  86.  
  87.   begin_sequence();                    /* perform the beginning sequence    */
  88.   draw_menu();
  89.   txt_scroll_over(400);                /* scroll up the menu screen         */
  90.   txt_set_act(TEXTPAGE1);              /* set first text page as active     */
  91.   txt_set_vis(TEXTPAGEACTIVE);         /* show active text page             */
  92.   txt_split(1023);                     /* restore screens to normal         */
  93.  
  94.   while (TRUE) {
  95.     kbd_clear();                       /* clear keyboard buffer             */
  96.     count = txt_get_num(25, 14, &choice, 1, '∙', "Type in your selection: ",
  97.                         LIGHTCYAN, LIGHTBLUE, "1");
  98.     if (count != -1 && choice == 1)
  99.       (*menuselect[choice-1])();       /* perform the desired demonstration */
  100.     else
  101.       break;                           /* else exit program                 */
  102.     draw_menu();
  103.   };
  104.  
  105.   exit(0);  /* executes the procedure "exit_sequence()" because of the line
  106.                "atexit(exit_sequence)" in procedure "begin_sequence"        */
  107. }
  108.  
  109. /*----------------------------------------------------------------------------
  110.  * Beginning sequence.
  111.  */
  112. void begin_sequence(void)
  113. {
  114.   char ch;                             /* generic character holder          */
  115.   byte i, j;                           /* cursor position holders           */
  116.  
  117.   /* allocate space for a generic string buffer */
  118.   buffer = (char *) malloc(BUFFERSPACE);
  119.  
  120.   /* check amount of available memory */
  121.   DASHES;                              /* print one line of dashes          */
  122.   if (coreleft() < 64000L) {
  123.     sprintf(buffer, ERR01, coreleft());
  124.     fprintf(stderr, buffer);           /* print low memory warning message  */
  125.     cur_get_coord_abs(&i, &j);         /* get the cursor position           */
  126.     while ((ch = case_up(getchre(i, j))) != 'Y' && ch != 'N' && ch != 13) {
  127.       beep();                          /* signal invalid keypress           */
  128.       txt_chr_erase(i, j, 1);          /* erase character                   */
  129.     }
  130.     if (ch != 'Y') {                   /* if 'Y' chosen                     */
  131.       fprintf(stderr, MSG01);          /*   print suggestion message        */
  132.       exit(1);                         /*   exit to DOS with ERRORLEVEL 1   */
  133.     }                                  /* else continue with program        */
  134.   }
  135.  
  136.   /* initialize The BEST Library and save old video mode
  137.    * set 25-line text mode (TEXT25) and initialize the mouse (TRUE)         */
  138.   oldmode = bestlib_init(TEXT25, TRUE);
  139.   txt_set_act(TEXTPAGELAST);           /* set last text page as active      */
  140.   txt_mem(TEXTSHOW, NULL);             /* write DOS screen to text page 2   */
  141.   txt_set_vis(TEXTPAGEACTIVE);         /* show active text page             */
  142.   txt_set_act(TEXTPAGE1);              /* set first text page as active     */
  143.  
  144.   /* store that status of the insert, caps, num, and scroll lock */
  145.   kbd_status_save();
  146.  
  147.   ms_show();                           /* show mouse cursor                 */
  148.   txt_blink(FALSE);                    /* enable 16 background colors       */
  149.   cur_off();                           /* hide the cursor                   */
  150.   atexit(exit_sequence);               /* define the exit procedure         */
  151. //txt_fade_out();                      /* fade current text screen to black */
  152. }
  153.  
  154. /*----------------------------------------------------------------------------
  155.  * Display the main menu.
  156.  */
  157. void draw_menu(void)
  158. {
  159.   txt_flood(WHITE, BLUE, " ");         /* flood with white fg and blue bg   */
  160.   txt_str_show(0, 0, "MOUSE", ALIGN_NONE);
  161.   txt_str_show(80, 0, "STRING", ALIGN_HORZ);
  162.   txt_str_show(80, 0, "TEXT MODE", ALIGN_RIGHT);
  163.   txt_str_show(0, 2, "Demonstration", ALIGN_HORZ);
  164.   txt_str_show(2, 5, "1) Text fading", ALIGN_NONE);
  165.   txt_str_show(0, 11, "<ESC> Exit to DOS", ALIGN_NONE);
  166. }
  167.  
  168. /*------------------